package org.tc.feign.storefront;

import org.gdtc.storefront.entity.Classification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.tc.feign.service.FeignClassificationService;

import java.util.List;

//@RequestMapping("/Classification")
@RestController
@CrossOrigin(origins = {"*"}, methods = {RequestMethod.GET, RequestMethod.POST}, allowCredentials = "true")
public class FeignClassificationController {
    @Autowired
    private FeignClassificationService feignClassificationService;

    /**
     * 根据分店id查询 三级分类id
     *
     * @param storeid 分店ID
     * @return
     */
    @RequestMapping("/selectThree")
    @ResponseBody
    public List<Classification> selectThree(@RequestParam Integer storeid, Integer classone, Integer classthree) {
        List<Classification> list = feignClassificationService.selectThree(storeid,classone,classthree);
        return list;
    }

    /**
     * 查询分店一级分类和分类ID
     *
     * @param storeid 分店ID
     * @return
     */
    @RequestMapping("/QueryClassone")
    public List<Classification> QueryClassone(Integer storeid) {
        List<Classification> list = feignClassificationService.QueryClassone(storeid);
        System.out.println(list.size()+"\t长度");
        return list;
    }

    /**
     * 查询分店二级分类和分类ID
     *
     * @param storeid
     * @return
     */
    @RequestMapping("/QueryClasstwo")
    @ResponseBody
    public List<Classification> QueryClasstwo(@RequestParam Integer storeid, @RequestParam Integer classone) {
        List<Classification> list = feignClassificationService.QueryClasstwo(storeid, classone);
        return list;
    }

    /**
     * 查询分店三级分类和分类ID
     *
     * @param storeid
     * @return
     */
    @RequestMapping("/QueryClassthree")
    @ResponseBody
    public List<Classification> QueryClassthree(@RequestParam Integer storeid, @RequestParam Integer classtwo) {
        List<Classification> list = feignClassificationService.QueryClassthree(storeid, classtwo);
        return list;
    }

    /**
     * 添加一级分类
     *
     * @param storeid      分店ID
     * @param classonename 分类内容
     * @return
     * @Param classone   一级分类ID
     */
    @RequestMapping("/InsClassone")
    @ResponseBody
    public int InsClassone(@RequestParam Integer storeid, @RequestParam String classonename) {
        int one = feignClassificationService.QueryClassoneLimit();
        int classone = one + 1;
        int count = feignClassificationService.InsClassone(storeid, classone, classonename);
        return count;
    }

    /**
     * 添加二级分类
     *
     * @param storeid      分店ID
     * @param classone     一级分类ID
     * @param classtwoname 二级分类内容
     * @return
     */
    @RequestMapping("/InsClasstwo")
    @ResponseBody
    public int InsClasstwo(@RequestParam Integer storeid, @RequestParam Integer classone, @RequestParam String classtwoname) {
        int two = feignClassificationService.QueryClasstwoLimit();
        int classtwo = two + 1;
        int count = feignClassificationService.InsClasstwo(storeid, classone, classtwo, classtwoname);
        return count;
    }

    /**
     * 添加三级分类
     *
     * @param storeid        分店ID
     * @param classone       一级分类ID
     * @param classtwo       二级分类ID
     * @param classthreename 三级分类内容
     * @return
     */
    @RequestMapping("/InsClassthree")
    @ResponseBody
    public int InsClassthree(@RequestParam Integer storeid, @RequestParam Integer classone, @RequestParam Integer classtwo, @RequestParam String classthreename) {
        int three = feignClassificationService.QueryClassthreeLimit();
        int classthree = three + 1;
        int count = feignClassificationService.InsClassthree(storeid, classone, classtwo, classthree, classthreename);
        return count;
    }

    /**
     * 删除一级分类
     *
     * @param classone 一级分类ID
     * @param storeid  分店ID
     * @return
     */
    @RequestMapping("/DelClassone")
    @ResponseBody
    public int DelClassone(@RequestParam Integer storeid, @RequestParam Integer classone) {
        int count = feignClassificationService.DelClassone(classone, storeid);
        return count;
    }

    /**
     * 删除二级分类
     *
     * @param classtwo 二级分类ID
     * @param storeid  分店ID
     * @return
     */
    @RequestMapping("/DelClasstwo")
    @ResponseBody
    public int DelClasstwo(@RequestParam Integer classtwo, @RequestParam Integer storeid) {
        int count = feignClassificationService.DelClasstwo(classtwo, storeid);
        return count;
    }

    /**
     * 删除三级分类ID
     *
     * @param classthree 三级分类ID
     * @param storeid    分店ID
     * @return
     */
    @RequestMapping("/DelClassthree")
    @ResponseBody
    public int DelClassthree(@RequestParam Integer classthree, @RequestParam Integer storeid) {
        int count = feignClassificationService.DelClassthree(classthree, storeid);
        return count;
    }
    /**
     * 删除三级分类ID
     *
     * @return
     */
    @RequestMapping("/selectIdByClassthreename")
    @ResponseBody
    public int selectIdByClassthreename(@RequestParam String classthreename) {
        int classthree = feignClassificationService.selectIdByClassthreename(classthreename);
        return classthree;
    }

    /**
     * 查询分店ID
     */
    @RequestMapping("/QueryStoreID")
    @ResponseBody
    public List<Classification> QueryStoreID() {
        List<Classification> list = feignClassificationService.selectAll();
        return list;
    }

    /**
     * 默认加载所有一级分类
     * 不用传入分店ID
     */
    @RequestMapping("/QueryClass")
    @ResponseBody
    public List<Classification> QueryClass() {
        List<Classification> list = feignClassificationService.QueryClass();
        return list;
    }

    /**
     * 默认加载所有二级分类
     * 不用传入分店ID
     */
    @RequestMapping("/QueryClasstwos")
    @ResponseBody
    public List<Classification> QueryClasstwo() {
        List<Classification> list = feignClassificationService.QueryClasstwos();
        return list;
    }

    /**
     * 默认加载所有三级分类
     * 不用传入分店ID
     */
    @RequestMapping("/QueryClassthrees")
    @ResponseBody
    public List<Classification> QueryClassthree() {
        List<Classification> list = feignClassificationService.QueryClassthrees();
        return list;
    }

}
